package com.ruoyi.lab.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lab.domain.LabOperateMessage;
import com.ruoyi.lab.service.ILabOperateMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实验室操作信息Controller
 * 
 * @author dn
 * @date 2024-01-01
 */
@RestController
@RequestMapping("/lab/labOperate")
public class LabOperateMessageController extends BaseController
{
    @Autowired
    private ILabOperateMessageService labOperateMessageService;

    /**
     * 查询实验室操作信息列表
     */
    @PreAuthorize("@ss.hasPermi('lab:labOperate:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabOperateMessage labOperateMessage)
    {
        startPage();
        List<LabOperateMessage> list = labOperateMessageService.selectLabOperateMessageList(labOperateMessage);
        return getDataTable(list);
    }

    /**
     * 导出实验室操作信息列表
     */
    @PreAuthorize("@ss.hasPermi('lab:labOperate:export')")
    @Log(title = "实验室操作信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabOperateMessage labOperateMessage)
    {
        List<LabOperateMessage> list = labOperateMessageService.selectLabOperateMessageList(labOperateMessage);
        ExcelUtil<LabOperateMessage> util = new ExcelUtil<LabOperateMessage>(LabOperateMessage.class);
        util.exportExcel(response, list, "实验室操作信息数据");
    }

    /**
     * 获取实验室操作信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('lab:labOperate:query')")
    @GetMapping(value = "/{operateId}")
    public AjaxResult getInfo(@PathVariable("operateId") Long operateId)
    {
        return success(labOperateMessageService.selectLabOperateMessageByOperateId(operateId));
    }

    /**
     * 根据实验室id查询操作信息 用于时间线
     * @param labId
     * @return
     */
    @PreAuthorize("@ss.hasPermi('lab:labOperate:list')")
    @GetMapping("/selectByLabId/{labId}")
    public AjaxResult selectByLabId(@PathVariable Long labId) {
        LabOperateMessage labOperateMessage = new LabOperateMessage();
        labOperateMessage.setLabId(labId);
        return AjaxResult.success(labOperateMessageService.selectLabOperateMessageList(labOperateMessage));
    }


    /**
     * 新增实验室操作信息
     */
    @PreAuthorize("@ss.hasPermi('lab:labOperate:add')")
    @Log(title = "实验室操作信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabOperateMessage labOperateMessage)
    {
        return toAjax(labOperateMessageService.insertLabOperateMessage(labOperateMessage));
    }

    /**
     * 修改实验室操作信息
     */
    @PreAuthorize("@ss.hasPermi('lab:labOperate:edit')")
    @Log(title = "实验室操作信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabOperateMessage labOperateMessage)
    {
        return toAjax(labOperateMessageService.updateLabOperateMessage(labOperateMessage));
    }

    /**
     * 删除实验室操作信息
     */
    @PreAuthorize("@ss.hasPermi('lab:labOperate:remove')")
    @Log(title = "实验室操作信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{operateIds}")
    public AjaxResult remove(@PathVariable Long[] operateIds)
    {
        return toAjax(labOperateMessageService.deleteLabOperateMessageByOperateIds(operateIds));
    }
}
